
import cv2
import numpy as np

if __name__ == '__main__':
    image = cv2.imread("C:\\Users\\20436\Desktop\kuli.jpg")
    # 灰度化
    image_gray = cv2.cvtColor(
        image,
        cv2.COLOR_BGR2GRAY
    )

    _,image_thresh=cv2.threshold(
        image_gray,
        102,
        255,
        cv2.THRESH_BINARY+cv2.THRESH_OTSU
    )
    image_canny = cv2.Canny(
        image_thresh,
        30,
        70
    )
    cirles=cv2.HoughCircles(
        image_canny,
        cv2.HOUGH_GRADIENT,
        1,
        15,
        param2=20,
        minRadius=20,
        maxRadius=41
    )
    for cirle in cirles:
        x,y,r=cirle[0]
        cv2.circle(
            image,
            (int(x),int(y)),
            int(r),
            (255,255,0),
            2,
            cv2.LINE_AA
        )

    cv2.imshow('contour_image_1', image)
    cv2.imwrite('contour_image_1.jpg', image)
    cv2.waitKey(0)